package com.budwk.app.sqfwV2.generator.centuryCity;

import cn.hutool.core.date.DateUtil;
import com.budwk.app.sqfw.enums.DownLoadFileNameEnum;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfwDoc.bo.SqfwExcelForSummaryBO;
import com.budwk.app.sqfwDoc.bo.SqfwExcelJudgeRes;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.SqfwExcelCreateCommonBO;
import com.budwk.app.sqfwV2.dto.image.ServiceStationExcelImageConfigBO;
import com.budwk.app.sqfwV2.dto.dto.OldCareServiceStationPdfDTO;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

public class CenturyCityOldCareServicePatrolExcelGenerator extends BaseTemplateExcelGenerator {

    @Override
    protected String getTemplateName() {
        return "jinYuanCenturyCity/oldCareServicePatrol.xlsx";
    }

    /**
     * 可以参照 {@link com.budwk.app.sqfw.enums.DownLoadFileNameEnum}
     *
     * @return 文件名名称
     */
    @Override
    public String getDownloadFileName() {
        return DownLoadFileNameEnum.OLD_CARE_SERVICE_PATROL.getName();
    }

    /**
     * 用户自定义excel基础参数，比如表头这样的公用数据
     *
     * @param excelParam       已经填充的基础数据据
     * @param excelCreateParam excel生成提供的原料
     */
    @Override
    protected void customerPopularSheetBaseParam(Map<String, Object> excelParam, SqfwExcelCreateCommonBO excelCreateParam) {

    }

    @Override
    protected void customerPopularSheetDataParam(List<Map<String, Object>> listMap, SqfwExcelCreateCommonBO excelCreateParam) {

    }

    @Override
    protected void completeExcelFileCreateParam(ExcelFileCreateParamBO excelFileCreateParam) {

    }

    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, SqfwExcelForSummaryBO forSummaryBO) {
        Sqfw_formSummary_new formSummary = forSummaryBO.getSqfwFormSummaryNew();
        OldCareServiceStationPdfDTO pdfDTO = (OldCareServiceStationPdfDTO) forSummaryBO.getCustomerPdfCreateField();

        String placeName = pdfDTO.getPlaceName();   // 服务站名称
        String address = pdfDTO.getAddress();

        if (StringUtils.isBlank(placeName)) placeName = "";
        if (StringUtils.isBlank(address)) address = "";

        if (formSummary.getCommunity().equals("龙吉社区")) {
            placeName = formSummary.getCommunity() + "养老服务站";
            address = "11-1-1-2";
        }

        String businessSituation = pdfDTO.getBusinessSituation();   // 备注

        rowDataMap.put("placeNameAndAddress", placeName + "  " + address);
        rowDataMap.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy-MM-dd HH:mm"));
        rowDataMap.put("businessSituation", businessSituation);
        rowDataMap.put("createUserName", formSummary.getCreateUserName());
    }

    /**
     * 如果在遍历之前就能够判断excel是否生成，那么就在这个方法中进行判断
     *
     * @param excelCreateParam excel生成所需的最为全面的数据
     * @param excelParam       excel已经填充的部分数据
     */
    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeErgodic(SqfwExcelCreateCommonBO excelCreateParam, Map<String, Object> excelParam) {
        List<SqfwExcelForSummaryBO> dataList = excelCreateParam.getDataList();
        SqfwExcelJudgeRes judgeRes = new SqfwExcelJudgeRes();
        judgeRes.setCreateConditionFlag(!dataList.isEmpty());
        judgeRes.setNotCreateMark("没有数据，不能下载");
        return judgeRes;
    }

    /**
     * 如果在遍历之后能够判断excel是否生成，那么就在这个方法中进行判断
     *
     * @param excelParam excel已经填充的部分数据
     */
    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeCreate(Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected Class<?> getImageConfigBO() {
        return ServiceStationExcelImageConfigBO.class;
    }
}
